<?php

namespace app\common\business;

use app\common\lib\Arr;
use app\common\lib\Str;
use app\common\lib\Time;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Exception;

class AdminPermission{

    public $model = null;

    public function __construct()
    {
        $this->model = new \app\common\model\mysql\AdminPermission();
    }

    /**
     * 获取当前登录用户对应权限的菜单
     * @param $adminId
     * @throws Exception
     */
    public function getPermission($adminId): array
    {
        $rule=(new AdminUser())->getAdminUserById($adminId)['role']['rules'];
        $menu=$this->model->getMenuListByRule($rule);
        $menu=$menu->isEmpty()?[]:$menu->toArray();
        return Arr::getTree($menu,'pid','childList');
    }
}
